package com.vchecker.iobd_checker.utils;

public class Decrypt {

	public static long ShiftLeft(long dw, int ln)
	{
		return (dw << ln) | (dw>>>(32 - ln));
	}

	// 四个字节数据加密
	public static int Encrypt_4Byte_To_4Byte_Production(byte[] Source_Str, byte[] Target_Str)
	{
		long Source_A,Target_A;

		Source_A = (Source_Str[3]&0xff)*0x1000000 + (Source_Str[1]&0xff)*0x10000 + (Source_Str[0]&0xff)*0x100 + (Source_Str[2]&0xff);
		Source_A = (Source_A+0x75363556)^0x78684243;
		Target_A =	((Source_A&0x20000000)>>19) | ((Source_A&0x00000400)<<19) |
				((Source_A&0x04000000)>>22) | ((Source_A&0x00000010)<<22) |
				((Source_A&0x01000000)>>2) | ((Source_A&0x00400000)<<2) |
				((Source_A&0x00100000)>>1) | ((Source_A&0x00080000)<<1) |
				((Source_A&0x00020000)>>6) | ((Source_A&0x00000800)<<6) |
				((Source_A&0x00000200)>>8) | ((Source_A&0x00000020)<<8) |
				((Source_A&0x00040000)>>6) | ((Source_A&0x00001000)<<6) |
				((Source_A&0x00010000)>>14) | ((Source_A&0x00000004)<<14) |
				((Source_A&0x00004000)>>8) | ((Source_A&0x00000040)<<8);
		Target_A = Target_A | (Source_A & 0xdaa0a1a9);
		Target_A = (Target_A+0x87975464)^0x47875457;
		Target_Str[0] = (byte) ((Target_A&0xff000000) >> 24);
		Target_Str[1] = (byte) ((Target_A&0x00ff0000) >> 16);
		Target_Str[2] = (byte) ((Target_A&0x0000ff00) >> 8);
		Target_Str[3] = (byte) (Target_A&0x000000ff);


		return 0;
	}

	public final static int fEncrypt_4Byte_To_4Byte_Production(byte[] Source_Str, byte[] Target_Str)
	{
		int Source_A;
		int Target_A;

		Source_A = Source_Str[3] * 0x1000000 + Source_Str[1] * 0x10000 + Source_Str[0] * 0x100 + Source_Str[2];
		Source_A = (Source_A + 0x75363556) ^ 0x78684243;
		Target_A = ((Source_A & 0x20000000)>>>19) | ((Source_A & 0x00000400) << 19) |
				((Source_A & 0x04000000)>>>22) | ((Source_A & 0x00000010) << 22) |
				((Source_A & 0x01000000)>>>2) | ((Source_A & 0x00400000) << 2) |
				((Source_A & 0x00100000)>>>1) | ((Source_A & 0x00080000) << 1) |
				((Source_A & 0x00020000)>>>6) | ((Source_A & 0x00000800) << 6) |
				((Source_A & 0x00000200)>>>8) | ((Source_A & 0x00000020) << 8) |
				((Source_A & 0x00040000)>>>6) | ((Source_A & 0x00001000) << 6) |
				((Source_A & 0x00010000)>>>14) | ((Source_A & 0x00000004) << 14) |
				((Source_A & 0x00004000)>>>8) | ((Source_A & 0x00000040) << 8);
		Target_A = Target_A | (Source_A & 0xdaa0a1a9);
		Target_A = (Target_A + 0x87975464) ^ 0x47875457;
		Target_Str[0] = (byte) ((Target_A & 0xff000000) >>> 24);
		Target_Str[1] = (byte) ((Target_A & 0x00ff0000) >>> 16);
		Target_Str[2] = (byte) ((Target_A & 0x0000ff00) >>> 8);
		Target_Str[3] = (byte) (Target_A & 0x000000ff);
		return 0;
	}

}
